package com.example.neusoft.yuejian.Activity;


import android.content.Context;

import android.content.Intent;
import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;
import android.widget.Button;

import android.widget.EditText;
import android.widget.Toast;

import com.example.neusoft.yuejian.Base.BaseListener;
import com.example.neusoft.yuejian.Base.BaseModel;

import com.example.neusoft.yuejian.Bean.Realbean;
import com.example.neusoft.yuejian.R;


public class Regist extends AppCompatActivity implements View.OnClickListener {
    private Button regist;
    private EditText phone,password,password1;
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regist);
        init();
        initEvent();
    }
    public void init(){
        phone=findViewById(R.id.phone);
        password=findViewById(R.id.password);
        password1=findViewById(R.id.passwprd1);

        regist=findViewById(R.id.regist);

    }
    public void initEvent(){

        regist.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.regist:
                String number=phone.getText().toString();
                String pass=password.getText().toString();
                String pass2=password1.getText().toString();
                if(number.length()!=11){
                    Toast.makeText(this,"输入的手机号有误",Toast.LENGTH_SHORT).show();}


                if(!pass.equals(pass2)){
                    Toast.makeText(this,"俩次输入的密码不一致",Toast.LENGTH_SHORT).show();
                }else {
                    requestRegist(number,pass);
                }

                break;

        }
    }

    public void requestRegist(String phone,String password){
        BaseModel<Realbean> model=new BaseModel<>();
        retrofit2.Call<Realbean> call=model.service.getregister(phone,password);
        model.callEnqueue(call,listener);
    }


    BaseListener<Realbean> listener=new BaseListener<Realbean>() {
        @Override
        public void onResponse(Realbean realbean) {
        if(realbean.getStatus().equals("注册成功")){
            String data=realbean.getDate();
            Toast.makeText(getApplicationContext(),data,Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(Regist.this,Login.class);
            startActivity(intent);
        }
        else {
            String data=realbean.getMessage();
            Toast.makeText(getApplicationContext(),data,Toast.LENGTH_SHORT).show();}
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(getApplicationContext(),"333333333333",Toast.LENGTH_SHORT).show();}

    };
}

